package com.lab.spring.topic2;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * Created with IntelliJ IDEA.
 * User: bsceran
 * Date: 5/22/13
 * Time: 11:30 AM
 * To change this template use File | Settings | File Templates.
 */
public class PriceCheckingPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object o, String s) throws BeansException {
        if(o instanceof Product) {
            Product product = (Product) o;
            //System.out.println("Price was " + product.getPrice());
            if(product.getPrice() < 0) {
                product.setPrice(0.0);
            }
        }
        return o;
    }

    @Override
    public Object postProcessAfterInitialization(Object o, String s) throws BeansException {
        if(o instanceof Product) {
            Product product = (Product) o;
        }
        return o;
    }
}
